import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Qt + ROS 2 Demo (Proxy Pattern)")

    Column {
        anchors.fill: parent
        anchors.margins: 10
        spacing: 15

        TextField {
            id: messageInput
            placeholderText: "Enter message to publish"
            width: parent.width
        }

        Button {
            text: "Publish to /qt_topic"
            width: parent.width
            onClicked: {
                // 【变化】调用rosProxy的方法
                rosProxy.publishMessage(messageInput.text)
            }
        }

        Text {
            id: receivedText
            // 【关键变化】直接绑定到rosProxy的属性上
            // 当C++中属性变化时，这里会自动更新
            text: rosProxy.receivedMessage || "Waiting for message from /ros_topic..."
            wrapMode: Text.WordWrap
            width: parent.width
        }
    }
}
